<template>
  <div class="logpage">
    <div class="login">
      <div class="login_name">宠物领养管理后台</div>
      <el-form
        :label-position="labelPosition"
        label-width="70px"
        :model="loginuser"
        :rules="rules"
      >
        <el-form-item label="账号" prop="name">
          <el-input
            v-model="loginuser.name"
            placeholder="请输入手机号"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="pass">
          <el-input
            type="password"
            v-model="loginuser.pass"
            autocomplete="off"
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="log_btn" @click="login"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: "LoginPage",
  data() {
    return {
      labelPosition: "right",
      // 手机号账号 密码
      loginuser: {
        name: "18847182253",
        pass: "18847182253",
      },
      // rules 可以自定义名称
      rules: {
        //trigger 触发事件  message 提示信息  required 规则属性表示字段必须存在于正在验证的源对象上（加上可以表示必填项，会有一个红色星星）。
        name: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          {
            pattern: /^1[3-9]\d{9}$/,
            message: "请输入正确的手机号",
            trigger: "blur",
          },
        ],
        pass: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            pattern: /[0-9]/,
            message: "请输入正确的密码",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    login() {
      if (
        this.loginuser.name === "18847182253" &&
        this.loginuser.pass === "18847182253"
      ) {
        this.$router.push({
          name: "home",
        });
        localStorage.setItem("loginuser", this.loginuser.name);
      } else {
        this.$message.error("输入错误，请输入正确的手机号或密码！");
      }
    },
  },
};
</script>

<style scoped lang="scss">
.logpage {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: palegoldenrod;
  background: url("./images/sugarglider06.jpg") no-repeat;
  background-size: 100% 100%;
}
.login {
  width: 300px;
  padding: 0px 30px 20px 0px;
  box-shadow: 0px 0 10px #666;
  background-color: #cde4e9;
  border-radius: 10px;
  .login_name {
    height: 50px;
    padding-left: 50px;
    font-weight: bolder;
    font-size: 20px;
    line-height: 50px;
    text-align: center;
    margin-bottom: 5px;
  }
  .log_btn {
    width: 230px;
  }
}
</style>